<!--
 * @Description: 
 * @Author: yucheng
 * @Date: 2024-07-22
 * @LastEditors: 余承
 * @LastEditTime: 2024-09-09
-->
<template>
    <div class="legend">
        <div class="text">地下水位埋深</div>
        <div class="color2values">
            <div class="color"></div>
            <div class="values">
                <span>{{ deeps.start }}m</span>
                <span>{{ deeps.end }}m</span>
            </div>
        </div>

    </div>
</template>

<script lang='ts' setup>
import { reactive, onMounted, onUnmounted } from 'vue'

const deeps = reactive({
    start: 0,
    end: 100
})
let mapWindow: any = null
let interval: any = null

const gerDeeps = () => {
    if (!mapWindow) return
    const start = Math.floor(+((mapWindow?.minDepth ?? 0) + '').substring(0, 10))
    const end = Math.ceil(+((mapWindow?.maxDepth ?? 0) + '').substring(0, 10))
    deeps.start = start
    deeps.end = end
}

onMounted(() => {
    interval = setInterval(() => {
        if (mapWindow) {
            gerDeeps()
        } else {
            mapWindow = (document.getElementById('map')! as HTMLIFrameElement).contentWindow!
            gerDeeps()
        }
    }, 1000)
})

onUnmounted(() => {
    clearInterval(interval)
})
</script>

<style scoped lang='scss'>
.legend {
    width: 240px;
    height: 92px;
    border-radius: 6px;
    padding: 6px 8px;
    background-color: rgba(0, 0, 0, 0.6);
    // background-color: red;
    color: #fff;

    .color2values {
        width: 100%;
        height: 40pxpx;
        margin-bottom: 10px;

        .color {
            width: 100%;
            height: 30px;
            background: linear-gradient(to left, rgb(0, 0, 128), rgb(0, 153, 255));
        }

        .values {
            display: flex;
            justify-content: space-between;
            width: 100%;
            padding-top: 4px;
        }
    }

    .text {
        display: flex;
        justify-content: center;
        // align-items: center;
        width: 100%;
        height: 26px;
        font-size: 14px;
    }
}
</style>